package com.lwb.eduorder.controller;


import com.lwb.commonutils.Row;
import com.lwb.eduorder.service.TPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-12-10
 */
@RestController
@RequestMapping("/eduorder/t-pay-log")
@CrossOrigin
public class TPayLogController {

    @Autowired
    private TPayLogService tPayLogService;

    //生成微信二维码接口
    @GetMapping("createNative/{orderNo}")
    public Row createNative(@PathVariable String orderNo) {
        Map map = tPayLogService.createNative(orderNo);
        return Row.SUCCESS().data(map);
    }

    //查询订单支付状态
    //参数：订单号，根据订单号查询，支付状态
    @GetMapping("getPayStatus/{orderNo}")
    public Row getPayStatus(@PathVariable String orderNo){
        Map<String,String> map = tPayLogService.getPayStatus(orderNo);
        if(map == null){
            return Row.ERROR().message("支付失败！");
        }
        if (map.get("trade_state").equals("SUCCESS")) {
            tPayLogService.updateOrderStatus(map);
            return Row.SUCCESS().message("支付成功！");
        }
        return Row.SUCCESS().code(25000).message("支付中！");
    }

}

